define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'paotui/posterlevel/index' + location.search,
                    add_url: 'paotui/posterlevel/add',
                    edit_url: 'paotui/posterlevel/edit',
                    del_url: 'paotui/posterlevel/del',
                    multi_url: 'paotui/posterlevel/multi',
                    import_url: 'paotui/posterlevel/import',
                    dragsort_url:'',
                    table: 'paotui_poster_level',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                sortOrder:'asc',
                search:false,
                commonSearch:false,
                columns: [
                    [

                        {field: 'id', title: __('Id')},
                        {field: 'level_name', title: __('等级名称'), operate: 'LIKE'},
                        {field: 'max_num', title: __('同时配送最大订单数')},
                        {
                            field: 'operate', title: __('Operate'), table: table,align:'left',
                            buttons:[
                                {

                                    name: 'edit', // 自定义编辑按钮
                                    title: __('编辑'),
                                    extend: 'data-area=\'["80%", "90%"]\'',
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    icon: 'fa fa-pencil',
                                    url: $.fn.bootstrapTable.defaults.extend.edit_url,
                                },
                                {
                                    visible:function (row) {
                                        if(row['id'] != 1){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                    name: 'del', // 自定义编辑按钮
                                    title: __('删除'),
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    confirm: '确认删除吗？',
                                    icon: 'fa fa-trash-o',
                                    url: $.fn.bootstrapTable.defaults.extend.del_url,
                                    success: function (data, ret) {
                                        table.bootstrapTable('refresh');
                                    },
                                },
                            ],events: Table.api.events.operate, formatter: function (value, row, index) {
                                return Table.api.formatter.operate.call(this, value, row, index);
                            }
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});